home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_9.zip / LIBR.C < prev    next >
C/C++ Source or Header  |  1993-07-27  |  43KB  |  1,446 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. /* libr - procedures for reading (in C format) ais and tre files*/
  10.  
  11. #include "hdr.h"
  12. #include "vars.h"
  13. #include "libhdr.h"
  14. #include "ifile.h"
  15. #include "dbxp.h"
  16. #include "chapp.h"
  17. #include "arithp.h"
  18. #include "dclmapp.h"
  19. #include "miscp.h"
  20. #include "smiscp.h"
  21. #include "setp.h"
  22. #include "libfp.h"
  23. #include "libp.h"
  24. #include "librp.h"
  25.  
  26. static void getlitmap(IFILE *, Symbol);
  27. static char *getmisc(IFILE *, Symbol, int);
  28. static void getrepr(IFILE * , Symbol);
  29. static void getnod(IFILE *, char *, Node, int);
  30. static void getnval(IFILE *, Node);
  31. static int *getuint(IFILE *, char *);
  32. static void getovl(IFILE *, Symbol);
  33. static void getsig(IFILE *, Symbol, int);
  34. static void getudecl(IFILE *, int);
  35. static Tuple add_tree_node(Tuple, Node);
  36. static void retrieve_tree_nodes(IFILE *, int, Tuple);
  37.  
  38. extern IFILE *TREFILE, *AISFILE, *STUBFILE, *LIBFILE;
  39.  
  40. Declaredmap getdcl(IFILE *ifile)            /*;getdcl*/
  41. {
  42.     Declaredmap d;
  43.     char    *id;
  44.     Symbol    sym;
  45.     int n = 0, vis, i;
  46.  
  47.     n = getnum(ifile, "dcl_is_map_defined");
  48.     if (n == 0) {
  49.         return (Declaredmap) 0;
  50.     }
  51.     n = getnum(ifile, "dcl-number-defined"); /* get item count */
  52.     d = dcl_new(n);
  53.     if (n == 0) return d;
  54.     for (i = 1; i <= n; i++) {
  55.         id = getstr(ifile, "sym-str");
  56.         sym = getsymref(ifile, "");
  57.         vis = getnum(ifile, "sym-vis");
  58.         dcl_put_vis(d, id, sym, vis);
  59.     }
  60.     return(d);
  61. }
  62.  
  63. static void getlitmap(IFILE *ifile, Symbol sym)                /*;gettlitmap*/
  64. /* called for na_enum to input literal map.
  65.  * The literal map is a tuple, entries consisting of string followed
  66.  * by integer.
  67.  */
  68. {
  69.     Tuple    tup;
  70.     int i, n;
  71.  
  72.     n = getnum(ifile, "litmap-n");
  73.     tup = tup_new(n);
  74.     for (i = 1; i <= n; i+=2) {
  75.         tup[i] = getstr(ifile, "litmap-str");
  76.         tup[i+1] = (char *) getnum(ifile, "litmap-value");
  77.     }
  78.     OVERLOADS(sym) = (Set) tup;
  79. }
  80.  
  81. static char *getmisc(IFILE *ifile, Symbol sym, int mval)            /*;getmisc*/
  82. {
  83.     /* read MISC information if present 
  84.  * MISC is integer except for package, in which case it is a triple.
  85.  * The first two components are integers, the last is  a tuple of
  86.  * symbols
  87.  */
  88.     int    nat, i, n;
  89.     Tuple  tup, stup;
  90.  
  91.     nat = NATURE(sym);
  92.     if ((nat == na_package || nat == na_package_spec)) {
  93.         if (mval) {
  94.             tup = tup_new(3);
  95.             tup[1] = (char *) getnum(ifile, "misc-package-1");
  96.             tup[2] = (char *) getnum(ifile, "misc-package-2");
  97.             n = getnum(ifile, "misc-package-tupsize");
  98.             stup = tup_new(n);
  99.             for (i = 1; i<= n; i++)
  100.                 stup[i] = (char *) getsymref(ifile, "misc-package-symref");
  101.             tup[3] = (char *) stup;
  102.             return (char *) tup;
  103.         }
  104.         else {
  105.             getnum(ifile, "misc");
  106.             return  (char *)MISC(sym);
  107.         }
  108.     }
  109.     else if ((nat == na_procedure || nat == na_function) && mval) {
  110.         tup = tup_new(2);
  111.         tup[1] = (char *) getnum(ifile, "misc-number");
  112.         tup[2] = (char *) getsymref(ifile, "misc-symref");
  113.         return (char *) tup;
  114.     }
  115.     else {
  116.         return  (char *)getnum(ifile, "misc");
  117.     }
  118. }
  119. static void getrepr(IFILE * ifile, Symbol sym)            /*;getrepr*/
  120. {
  121.     /* read int representation information if present */
  122.  
  123.     int     repr_tag, i, n;
  124.     Tuple     align_mod_tup,align_tup,repr_tup;
  125.     Tuple     tup4;
  126.  
  127.     repr_tag = getnum(ifile, "repr-type");
  128.     if (repr_tag != -1) {
  129.             if (repr_tag == TAG_RECORD)     { /* record type */
  130.                 repr_tup = tup_new(4);
  131.                 repr_tup[1] = (char *) TAG_RECORD;
  132.                    repr_tup[2] = (char *) getnum(ifile,"repr-rec-size");
  133.                 align_mod_tup = tup_new(2);
  134.                 align_mod_tup[1] = (char *) getnum(ifile,"repr-rec-mod");
  135.                 n = getnum(ifile,"repr-align_tup_size");
  136.                 align_tup = tup_new(0);
  137.                 for (i=1; i<=n; i++) {
  138.                     tup4 = tup_new(4);
  139.                     tup4[1] = (char *) getsymref(ifile,"repr-rec-align-1");
  140.                     tup4[2] = (char *) getnum(ifile,"repr-rec-align-2");
  141.                     tup4[3] = (char *) getnum(ifile,"repr-rec-align-3");
  142.                     tup4[4] = (char *) getnum(ifile,"repr-rec-align-4");
  143.                     align_tup = tup_with(align_tup, (char *) tup4);
  144.                 }
  145.                 align_mod_tup[2] = (char *) align_tup;
  146.                    repr_tup[4] = (char *) align_mod_tup;
  147.                 REPR(sym) = repr_tup;
  148.             }
  149.             else if (repr_tag == TAG_ACCESS || 
  150.                      repr_tag == TAG_TASK) { /* access or task type */
  151.                 repr_tup = tup_new(3);
  152.                 repr_tup[1] = (char *) repr_tag;
  153.                  repr_tup[2] = (char *) getnum(ifile, "repr-size-2");
  154.                 repr_tup[3] = (char *) getnodref(ifile, "repr-storage-size");
  155.                 REPR(sym) = repr_tup;
  156.             }
  157.             else {         /* non-record, non-access, non-task type */
  158.                 n = getnum(ifile, "repr-tup-size");
  159.                 repr_tup = tup_new(n);
  160.                 repr_tup[1] = (char *) repr_tag;
  161.                 for (i=2; i <= n; i++)
  162.                     repr_tup[i] = (char *) getnum(ifile, "repr-info");
  163.                 REPR(sym) = repr_tup;
  164.             }
  165.     }
  166. }
  167.  
  168.  
  169. static void getnod(IFILE *ifile, char *desc, Node node, int unum)    /*;getnod*/
  170. {
  171.     /* 
  172.      * Read information for the node from a file (ifile)
  173.      * Since all the nodes in the tree all have the same N_UNIT value, 
  174.      * the node can be read from the file in a more compact format.
  175.      * The N_UNIT of the node itself and of its children (N_AST1...) need not
  176.      * be read only their N_SEQ filed needs to be read. There is one 
  177.      * complication of this scheme. OPT_NODE which is (seq=1, unit=0) will
  178.      * conflict with (seq=1,unit=X)  of current unit. Therefore, in this case a 
  179.      * sequence # of -1 will signify OPT_NODE.
  180.      */
  181.     int i;
  182.     short    nk, num1, num2, has_n_list;
  183.     Tuple    ltup;
  184.     short    fnum[24], fnums, fnumr=0;
  185.  
  186.     /* copy standard info */
  187.     fnums = getnum(ifile, desc);
  188.     /*fread((char *) &fnums, sizeof(short), 1, ifile->fh_file);*/
  189.     fread((char *) fnum,  sizeof(short), fnums, ifile->fh_file);
  190.     if (fnums == 0) {
  191.         chaos("getnod-fnums-zero");
  192.     }
  193.     fnumr = 0;
  194.     nk = fnum[fnumr++];
  195.     N_KIND(node) = nk;
  196.     N_SEQ(node) = fnum[fnumr++];
  197.     N_UNIT(node) = unum;
  198. #ifdef DEBUG
  199.     if (trapns>0 && N_SEQ(node)== trapns && N_UNIT(node) == trapnu) trapn(node);
  200. #endif
  201.  
  202.     N_SPAN0(node) = N_SPAN1(node) = 0;
  203.  
  204.     if (N_LIST_DEFINED(nk)) {
  205.         has_n_list = fnum[fnumr++];
  206.         ltup = (has_n_list) ? tup_new(has_n_list - 1) : (Tuple) 0;
  207.     }
  208.     else {
  209.         has_n_list = 0;
  210.     }
  211.     /* ast fields */
  212.     /* See comment above for description of compact format of node */
  213.     N_AST1(node) = N_AST2(node) = N_AST3(node) = N_AST4(node) = (Node)0;
  214.     if (N_AST1_DEFINED(nk)) {
  215.         num1 = fnum[fnumr++];
  216.         N_AST1(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
  217.     }
  218.     if (N_AST2_DEFINED(nk)) {
  219.         num1 = fnum[fnumr++];
  220.         N_AST2(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
  221.     }
  222.     if (N_AST3_DEFINED(nk)) {
  223.         num1 = fnum[fnumr++];
  224.         N_AST3(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
  225.     }
  226.     if (N_AST4_DEFINED(nk)) {
  227.         num1 = fnum[fnumr++];
  228.         N_AST4(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
  229.     }
  230.  
  231.     if (N_UNQ_DEFINED(nk)) {
  232.         num1 = fnum[fnumr++]; 
  233.         num2 = fnum[fnumr++];
  234.         if (num1>0 || num2>0)
  235.             N_UNQ(node) = getsymptr(num1, num2);
  236.     }
  237.     if (N_TYPE_DEFINED(nk)) {
  238.         num1 = fnum[fnumr++]; 
  239.         num2 = fnum[fnumr++];
  240.         if (num1>0 || num2>0) {
  241.             N_TYPE(node) = getsymptr(num1, num2);
  242.         }
  243.     }
  244.  
  245.     /* read out n_list if needed */
  246.     if (has_n_list > 0) {
  247.         for (i = 1; i<has_n_list; i++) {
  248.             ltup[i] = (char *) getnodref(ifile, "n-list-nodref");
  249.         }
  250.         if (ltup != (Tuple)0) {
  251.             N_LIST(node) = ltup;
  252.         }
  253.     }
  254.     if (N_VAL_DEFINED(nk))
  255.         getnval(ifile, node);
  256. }
  257.  
  258. Node getnodref(IFILE *ifile, char *desc)            /*;getnodref*/
  259. {
  260.     Node    node;
  261.     int    seq, unit;
  262.  
  263.     /* 
  264.      * OPT_NODE is node in unit 0 with sequence 1, and needs
  265.      * no special handling here
  266.      */
  267.     seq = getnum(ifile, "nref-seq");
  268.     unit = getnum(ifile, "nref-unt");
  269.     if (seq == 1 && unit == 0) {
  270.         return OPT_NODE;
  271.     }
  272.     else {
  273.         node = getnodptr(seq, unit);
  274. #ifdef DEBUG
  275.         if (trapns>0 && trapns == seq && trapnu == unit) trapn(node);
  276. #endif
  277.     }
  278.     return node;
  279. }
  280.  
  281. static void getnval(IFILE *ifile, Node node)                /*;getnval*/
  282. {
  283.     /* read N_VAL field for node to AISFILE */
  284.     int        nk, ck;
  285.     Const    con;
  286.     char    *nv;
  287.     Tuple    tup;
  288.     int        i, n, *rn, *rd;
  289.     double    doub;
  290.     Symbolmap   smap;
  291.     Symbol    s1, s2;
  292.  
  293.     nv = NULL;       /* gs nov 1: added to avoid setting N_VAL incorrectly
  294.                         at end of this routine */
  295.     swit